Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nextjs): Give app router prefetch requests a http.server.prefetch op #13600

Merged
merged 12 commits into from
Sep 10, 2024

Conversation

lforst
Copy link
Member

@lforst lforst commented Sep 5, 2024

Ref (not complete fix) #13596

This gives Next.js prefetch requests a http.server.prefetch op, when a Next-Router-Prefetch: 1 header is present.

In some situations Next.js doesn't seem to attach the header for prefetch requests. Seems like it is only attached when the current route is a dynamic route.

Copy link
Contributor

github-actions bot commented Sep 5, 2024

size-limit report 📦

Path Size % Change Change
@sentry/browser 22.52 KB - -
@sentry/browser - with treeshaking flags 21.3 KB - -
@sentry/browser (incl. Tracing) 34.78 KB - -
@sentry/browser (incl. Tracing, Replay) 71.23 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 61.66 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 75.58 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 88.3 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback, metrics) 90.14 KB - -
@sentry/browser (incl. metrics) 26.83 KB - -
@sentry/browser (incl. Feedback) 39.6 KB - -
@sentry/browser (incl. sendFeedback) 27.19 KB - -
@sentry/browser (incl. FeedbackAsync) 31.9 KB - -
@sentry/react 25.28 KB - -
@sentry/react (incl. Tracing) 37.75 KB - -
@sentry/vue 26.72 KB - -
@sentry/vue (incl. Tracing) 36.66 KB - -
@sentry/svelte 22.65 KB - -
CDN Bundle 23.77 KB - -
CDN Bundle (incl. Tracing) 36.49 KB - -
CDN Bundle (incl. Tracing, Replay) 70.91 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 76.22 KB - -
CDN Bundle - uncompressed 69.63 KB - -
CDN Bundle (incl. Tracing) - uncompressed 108.2 KB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 219.87 KB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 233.06 KB - -
@sentry/nextjs (client) 37.51 KB - -
@sentry/sveltekit (client) 35.36 KB - -
@sentry/node 120.5 KB +0.05% +50 B 🔺
@sentry/node - without tracing 92.77 KB +0.06% +52 B 🔺
@sentry/aws-serverless 102.48 KB +0.06% +57 B 🔺

View base workflow run

@lforst
Copy link
Member Author

lforst commented Sep 10, 2024

This is a probabilistic feature because for various reasons I wasn't able to write tests for it:

  • The HTTP integration doesn't work in the Next.js 15 e2e tests for some reason.
  • Next.js 14 doesn't give us access to the header and the HTTP integration doesn't work at all in that version.
  • I couldn't get Next.js 13 to do prefetches that are picked up by the SDK.

Timebox overflow -> abort mission. Highly frustrating, I am done trying to get this to work.

@lforst lforst marked this pull request as ready for review September 10, 2024 11:26
*/
function isKnownPrefetchRequest(req: HTTPModuleRequestIncomingMessage): boolean {
// Currently only handles Next.js prefetch requests but may check other frameworks in the future.
return req.headers['next-router-prefetch'] === '1';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we look at the Sec-Purpose header instead? This should work with all header types.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Purpose

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait it's not standardized 😭 https://chromestatus.com/feature/6247959677108224

@lforst lforst merged commit f7c033a into develop Sep 10, 2024
130 checks passed
@lforst lforst deleted the lforst-different-op-for-prefetch branch September 10, 2024 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants